package com.nightpiter.model.reader.xml;

import static com.nightpiter.controller.log.Logger.logException;

import java.io.IOException;
import java.io.InputStream;

import com.nightpiter.model.MetroModel;
import com.nightpiter.model.exceptions.BuilderException;
import com.nightpiter.model.exceptions.ModelNotAssignedBuilderException;
import com.nightpiter.model.reader.MetroModelReader;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 */
public abstract class XmlReader extends MetroModelReader {

	public static final String ROOT = "map";
	public static final String CONTENT = "content";
	public static final String STATIONS = "stations";
	public static final String STATION = "station";
	public static final String SCHEDULE = "schedule";
	public static final String POSITION = "position";
	public static final String LOCATION = "location";
	public static final String NAME = "name";
	public static final String LINES = "lines";
	public static final String LINE = "line";
	public static final String TRANSFERS = "transfers";
	public static final String TRANSFER = "transfer";
	public static final String TUNNELS = "tunnels";
	public static final String TUNNEL = "tunnel";
	public static final String CITY = "city";
	public static final String DESCRIPTION = "description";
	public static final String VERSION = "version";
	public static final String AUTHORS = "authors";
	public static final String AUTHOR = "author";
	public static final String NOTE = "note";
	public static final String ID_ATTR = "id";
	public static final String X_ATTR = "x";
	public static final String Y_ATTR = "y";
	public static final String LATITUDE_ATTR = "latitude";
	public static final String LONGITUDE_ATTR = "longitude";
	public static final String OPEN_ATTR = "open";
	public static final String CLOSE_ATTR = "close";
	public static final String FROM_ATTR = "from";
	public static final String TO_ATTR = "to";
	public static final String SMOOTH_ATTR = "smooth";
	public static final String TIME_ATTR = "time";
	public static final String LINE_ATTR = "line";
	public static final String COLOR_ATTR = "color";
	public static final String LAST_MODIFIED_ATTR = "last-modified";
	public static final String DX_ATTR = "dx";
	public static final String DY_ATTR = "dy";
	public static final String VISIBLE_ATTR = "visible";
	public static final String ANGLE_ATTR = "angle";

	/**
	 * protected constructor
	 * 
	 * @throws ModelNotAssignedBuilderException
	 */
	protected XmlReader(MetroModel model)
			throws ModelNotAssignedBuilderException {
		super(model);
	}

	protected void readStream(InputStream inputStream) throws BuilderException {
		try {
			parse(inputStream);
		} catch (IOException e) {
			logException(e);
		}

		modelBuilder.buildModel();
	}

	protected abstract void parse(InputStream inputStream) throws IOException;

}
